/**
	License:		Artistic license 2.0 (see license.txt, also available online at http://www.perlfoundation.org/artistic_license_2_0)
	Authors:		OrbitalLab (http://www.orbitallab.ru/moonglide/), 2007-2009

	File:			controllers.d
	Description:	mouse, kb (joystick?) stuff
	Date:			11.04.2008 by Digited
**/
module moonglide.core.Controllers;

import moonglide.math.MoonMath;

version( Windows )
{
	import tango.sys.win32.UserGdi;

	alias VK_BACK			_KB_BACKSPACE;
	alias VK_TAB			_KB_TAB;

	alias VK_CLEAR			_KB_CLEAR;
	alias VK_RETURN			_KB_RETURN;

	alias VK_SHIFT			_KB_SHIFT;
	alias VK_CONTROL		_KB_CONTROL;

	alias VK_ESCAPE			_KB_ESCAPE;

	alias VK_SPACE		    _KB_SPACE;
	alias VK_PRIOR		    _KB_PRIOR;
	alias VK_NEXT			_KB_NEXT;
	alias VK_END			_KB_END;
	alias VK_HOME			_KB_HOME;
	alias VK_LEFT			_KB_LEFT;
	alias VK_UP				_KB_UP;
	alias VK_RIGHT			_KB_RIGHT;
	alias VK_DOWN			_KB_DOWN;
	alias VK_EXECUTE		_KB_EXECUTE;

	alias VK_INSERT			_KB_INSERT;
	alias VK_DELETE			_KB_DELETE;

	alias VK_NUMPAD0		_KB_NUMPAD0;
	alias VK_NUMPAD1		_KB_NUMPAD1;
	alias VK_NUMPAD2		_KB_NUMPAD2;
	alias VK_NUMPAD3		_KB_NUMPAD3;
	alias VK_NUMPAD4		_KB_NUMPAD4;
	alias VK_NUMPAD5		_KB_NUMPAD5;
	alias VK_NUMPAD6		_KB_NUMPAD6;
	alias VK_NUMPAD7		_KB_NUMPAD7;
	alias VK_NUMPAD8		_KB_NUMPAD8;
	alias VK_NUMPAD9		_KB_NUMPAD9;
	alias VK_MULTIPLY		_KB_MULTIPLY;
	alias VK_ADD			_KB_ADD;
	alias VK_SEPARATOR		_KB_SEPARATOR;
	alias VK_SUBTRACT		_KB_SUBTRACT;
	alias VK_DECIMAL		_KB_DECIMAL;
	alias VK_DIVIDE			_KB_DIVIDE;
	alias VK_F1				_KB_F1;
	alias VK_F2				_KB_F2;
	alias VK_F3				_KB_F3;
	alias VK_F4				_KB_F4;
	alias VK_F5				_BK_F5;
	alias VK_F6				_KB_F6;
	alias VK_F7				_KB_F7;
	alias VK_F8				_KB_F8;
	alias VK_F9				_KB_F9;
	alias VK_F10			_KB_F10;
	alias VK_F11			_KB_F11;
	alias VK_F12			_KB_F12;

	alias VK_NUMLOCK		_KB_NUMLOCK;
	alias VK_SCROLL			_KB_SCROLL;

	alias VK_LSHIFT			_KB_LSHIFT;
	alias VK_RSHIFT			_KB_RSHIFT;
	alias VK_LCONTROL		_KB_LCONTROL;
	alias VK_RCONTROL		_KB_RCONTROL;
}
else version( linux )
{
	import X11.keysymdef;

	alias XK_BackSpace		_KB_BACKSPACE;
	alias XK_Tab			_KB_TAB;

	alias XK_Clear			_KB_CLEAR;
	alias XK_Return			_KB_RETURN;
	alias XK_Pause			_KB_PAUSE;

	alias XK_Shift_L		_KB_LSHIFT;
	alias XK_Shift_R		_KB_RSHIFT;
	alias XK_Control_L		_KB_LCONTROL;
	alias XK_Control_R		_KB_RCONTROL;
	alias XK_Meta_L			_KB_LMETA;
	alias XK_Meta_R			_KB_RMETA;
	alias XK_Alt_L			_KB_LALT;
	alias XK_Alt_R			_KB_RALT;
	alias XK_Super_L		_KB_LSUPER;
	alias XK_Super_R		_KB_RSUPER;
	alias XK_Hyper_L		_KB_LHYPER;
	alias XK_Hyper_R 		_KB_RHYPER;

	alias XK_Escape			_KB_ESCAPE;

	alias XK_Multi_key		_KB_SPACE;
	alias XK_Prior			_KB_PRIOR;
	alias XK_Next			_KB_NEXT;
	alias XK_End			_KB_END;
	alias XK_Home			_KB_HOME;
	alias XK_Left			_KB_LEFT;
	alias XK_Up				_KB_UP;
	alias XK_Right			_KB_RIGHT;
	alias XK_Down			_KB_DOWN;
	alias XK_Execute		_KB_EXECUTE;

	alias XK_Insert			_KB_INSERT;
	alias XK_Delete			_KB_DELETE;
	alias XK_Break			_KB_BREAK;

	alias XK_KP_0			_KB_NUMPAD0;
	alias XK_KP_1			_KB_NUMPAD1;
	alias XK_KP_2			_KB_NUMPAD2;
	alias XK_KP_3			_KB_NUMPAD3;
	alias XK_KP_4			_KB_NUMPAD4;
	alias XK_KP_5			_KB_NUMPAD5;
	alias XK_KP_6			_KB_NUMPAD6;
	alias XK_KP_7			_KB_NUMPAD7;
	alias XK_KP_8			_KB_NUMPAD8;
	alias XK_KP_9			_KB_NUMPAD9;
	alias XK_KP_Multiply	_KB_MULTIPLY;
	alias XK_KP_Add			_KB_ADD;
	alias XK_KP_Separator	_KB_SEPARATOR;
	alias XK_KP_Subtract	_KB_SUBTRACT;
	alias XK_KP_Decimal		_KB_DECIMAL;
	alias XK_KP_Divide		_KB_DIVIDE;

	alias XK_F1				_KB_F1;
	alias XK_F2				_KB_F2;
	alias XK_F3				_KB_F3;
	alias XK_F4				_KB_F4;
	alias XK_F5				_BK_F5;
	alias XK_F6				_KB_F6;
	alias XK_F7				_KB_F7;
	alias XK_F8				_KB_F8;
	alias XK_F9				_KB_F9;
	alias XK_F10			_KB_F10;
	alias XK_F11			_KB_F11;
	alias XK_F12			_KB_F12;

	alias XK_Num_Lock		_KB_NUMLOCK;
	alias XK_Scroll_Lock	_KB_SCROLL;
}

//=============================================================
/// enum of mouse button codes
//=============================================================
enum EMouseKeys
{
	_MB_LEFT = 0,
	_MB_MIDDLE,
	_MB_RIGHT,
	_MB_EX1,
	_MB_EX2,
	_MB_EX3,
	_MB_EX4,
	_MB_EX5,
	_MB_EX6,
	_MB_EX7,
	_MB_EX8,
	_MB_EX9
}

//=============================================================
/// Mouse state struct
//=============================================================
struct SMouseState
{
	bool	Keys[20];			/// mouse keys state: true == pressed, false == not
	int		Wheel;				/// mouse wheel state
	int		x, y;

	void cleanStats()
	{
		x = y = Wheel = 0;
	}
}

//=============================================================
/// keyboard state struct
//=============================================================
struct SKeyboardState
{
	bool[int] keys;

	bool opIndex( uint keycode )
	{
		if( keycode in keys )
			return keys[ keycode ];
		else
			return false;
	}

	void opCall( uint keycode, bool state )
	{
		keys[keycode] = state;
	}
}

//--------------------------------------------------------------------------------------------------
SMouseState		mouseState;			/// current mouse controller state
SKeyboardState	keyboardState;		/// current keyboard controller state
//--------------------------------------------------------------------------------------------------挀
